import React, { useEffect, useState } from 'react';
import { Table } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { connect } from 'umi';

interface DataType {
  key: string;
  nationalLevel: number;
  provincialLevel: number;
  universityLevel: number;
  instituteLevel: number;
  totalScore: number;
}

const columns: ColumnsType<DataType> = [
  {
    title: '国家级',
    dataIndex: 'nationalLevel',
    key: 'nationalLevel',
  },
  {
    title: '省部级',
    dataIndex: 'provincialLevel',
    key: 'provincialLevel',
  },
  {
    title: '校级',
    dataIndex: 'universityLevel',
    key: 'universityLevel',
  },
  {
    title: '院级',
    key: 'instituteLevel',
    dataIndex: 'instituteLevel',
  },
  {
    title: '总成绩',
    key: 'totalScore',
    dataIndex: 'totalScore',
  },
];

const SecondaryGrades: React.FC<any> = (props: any) => {
  const [data, setData] = useState<DataType[]>([]);
  const getAllList = () => {
    if (props.dispatch) {
      props.dispatch({
        //路径：model的namespace+effects函数名
        type: 'Model_StudentAnalysisStudentModel/getGradeSummaryClassTwoEffects',
        payload: {
          data: JSON.parse(props.user.currrentuser).account,
          callback: (value: any) => {
            setData(value);
          },
        },
      });
    }
  };
  useEffect(() => {
    if (props.user.currrentuser.length != 0) {
      console.log(JSON.parse(props.user.currrentuser));
      getAllList();
    }
  }, [props]);
  return (
    <div>
      <Table
        columns={columns}
        dataSource={data}
        pagination={{ hideOnSinglePage: true }}
      />
    </div>
  );
};

export default connect(({ Model_SecondExampleModel, user }: any) => ({
  Model_SecondExampleModel,
  user,
}))(SecondaryGrades);
